﻿package mortal.game.view.rebate.openNewSerSevenDay.panels
{
    import com.gengine.core.frame.*;
    import com.mui.controls.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;

    public class OpenNewSerSevTop extends GSprite
    {
        protected var bg:GImageBitmap;
        protected var _tDay1:BitmapNumberText;
        protected var _tiemDes:GImageBitmap;
        protected var _tDay2:BitmapNumberText;
        protected var _day:BitmapNumberText;
        protected var _hour:BitmapNumberText;
        protected var _min:BitmapNumberText;
        protected var _title:GImageBitmap;
        protected var _notOpenTip:GImageBitmap;
        private var _secT:SecTimer;
        private var _timeTab:int = -1;

        public function OpenNewSerSevTop()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.bg = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevDay, 0, 0, this);
            this._tDay1 = UIFactory.bitmapNumberText(130, 6, "OpenNewSerSevNum.png", 38, 43, -18, this, 9, 1);
            this._tDay1.text = "7";
            this._tiemDes = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevTopTimeDes, 13, 50, this);
            this._tDay2 = UIFactory.bitmapNumberText(385, 8, "OpenNewSerSevNum.png", 38, 43, -18, this, 9, 1);
            this._tDay2.text = "7";
            this._day = UIFactory.bitmapNumberText(140, 47, "investmentNum.png", 24, 30, -7, this, 9, 1);
            this._day.text = "07";
            this._hour = UIFactory.bitmapNumberText(202, 46, "investmentNum.png", 24, 30, -7, this, 9, 1);
            this._hour.text = "23";
            this._min = UIFactory.bitmapNumberText(281, 47, "investmentNum.png", 24, 30, -7, this, 9, 1);
            this._min.text = "59";
            this._title = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevMinT1, 461, 9, this);
            this._notOpenTip = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevTopNotOpen, 135, 49, this);
            this._secT = new SecTimer(1);
            this._secT.addListener(TimerType.ENTERFRAME, this.timeCk);
            this.activeOpen(false);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.bg = null;
            this._tDay1 = null;
            this._tiemDes = null;
            this._tDay2 = null;
            this._day = null;
            this._hour = null;
            this._min = null;
            this._title = null;
            this._notOpenTip = null;
            this._secT.dispose();
            this._secT = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public function updateTop(param1:Object, param2:int) : void
        {
            if (param1.dayNum == 99 || param1.dayNum == 100)
            {
                this.bg.imgUrl = "OpenNewSerSevDayAll7.swf";
                var _loc_3:Boolean = false;
                this._tDay2.visible = false;
                this._tDay1.visible = _loc_3;
            }
            else
            {
                this.bg.imgUrl = "OpenNewSerSevDay.swf";
                var _loc_3:Boolean = true;
                this._tDay2.visible = true;
                this._tDay1.visible = _loc_3;
                var _loc_3:* = "" + param1.dayNum;
                this._tDay2.text = "" + param1.dayNum;
                this._tDay1.text = _loc_3;
            }
            this._title.imgUrl = "OpenNewSerSevMinT" + param1.dayNum + ".swf";
            this.updateTime(param2);
            return;
        }// end function

        private function updateTime(param1:int) : void
        {
            this._timeTab = param1;
            var _loc_2:* = Cache.instance.openServerSevenDay.sevenDayTabArr[this._timeTab];
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:* = OpenServerSevenDayUtil.getCountDownTime(_loc_2.dayNum);
            if (this._timeTab == 0 || this._timeTab == 1)
            {
                this.timeCk(null);
                this.activeOpen(true);
            }
            else if (OpenServerSevenDayUtil.isTodayByTabIndex(this._timeTab) == 0)
            {
                this.timeCk(null);
                this.activeOpen(true);
            }
            else
            {
                this.activeOpen(false);
            }
            return;
        }// end function

        private function timeCk(param1:SecTimer) : void
        {
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            if (this._timeTab == -1)
            {
                this._secT.stop();
                return;
            }
            var _loc_2:* = Cache.instance.openServerSevenDay.sevenDayTabArr[this._timeTab];
            if (_loc_2 == null)
            {
                return;
            }
            if (this._timeTab == 0 || this._timeTab == 1)
            {
                _loc_3 = OpenServerSevenDayUtil.get7dayCountDownTime();
            }
            else
            {
                _loc_3 = OpenServerSevenDayUtil.getCountDownTime(_loc_2.dayNum);
            }
            _loc_4 = _loc_3[3];
            this._day.text = "" + _loc_3[0];
            this._hour.text = "" + _loc_3[1];
            this._min.text = "" + _loc_3[2];
            if (_loc_4 > 0)
            {
                if (this._secT.running == false)
                {
                    this._secT.start();
                }
            }
            else
            {
                this._secT.stop();
            }
            return;
        }// end function

        private function activeOpen(param1:Boolean) : void
        {
            var _loc_2:* = param1;
            this._min.visible = param1;
            var _loc_2:* = _loc_2;
            this._hour.visible = _loc_2;
            var _loc_2:* = _loc_2;
            this._day.visible = _loc_2;
            this._tiemDes.visible = _loc_2;
            this._notOpenTip.visible = !param1;
            return;
        }// end function

    }
}
